Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix lint #1529

Merged
merged 29 commits into from
Nov 24, 2022
Merged

Fix lint #1529

merged 29 commits into from
Nov 24, 2022

Conversation

DonggeLiu
Copy link
Contributor

Based on and required by #1526.

This PR fixes new lint errors from the latest pylint, which is required as #1526 upgrades Python to 3.10.
I reckon I have fixed all meaningful errors in the FuzzBench framework, not sure if the rest is worth fixing or could be ignored.

The rest lint errors are:

  1. From individual fuzzers (e.g., fuzzers/*);
  2. In the database directory (i.e., database/*);
  3. trivial errors:
    • conventional naming (e.g., df doesn't conform to snake_case naming style, but is common for pandas.dataframe).
    • too-few-public-methods (e.g., Too few public methods).
    • Using the global statement.
    • Improper Consider using 'with' for resource-allocating operations, e.g., with Popen, urlopen.
    • Improper Using open without explicitly specifying an encoding, e.g., when opening a binary file.

Could you please take a look at the rest errors and let me know which one is worth fixing?
Otherwise, I will find a way to let pylint ignore them in the future.

@DonggeLiu
Copy link
Contributor Author

It seems you will need to pull this branch and run make presubmit locally to see the errors.
Do not trust the 'All checks have passed' message here, there are quite many errors.

Copy link
Contributor

@jonathanmetzman jonathanmetzman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this.
i think we will need to discuss this offline.
I have some concerns. Mainly, why update .pylintrc?

# paths.
#
# Files under alembic are generated and are nonconforming.
ignore=alembic
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why get rid of stuff like this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pylintrc was generated automatically with the latest version of pylint, I am working on manually merging our old settings back so that we can have:

  1. The default settings of the latest pylint
  2. The same setting from us in the past.

.pylintrc Outdated
jobs=0
# number of processors available to use, and will cap the count on Windows to
# avoid hangs.
jobs=1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No we don't care about windows.

Copy link
Contributor

@jonathanmetzman jonathanmetzman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most changes ok to land whenever (as long as CI passes without the .pylintrc change)

import numpy as np
import Orange
import seaborn as sns

from matplotlib import colors
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did google's styleguide get rid of alphabetical order imports? It looks like it might have.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I remember pylint specifically requested me to put this at the top (which also surprised me), because it is an external import.

@@ -122,15 +122,15 @@ def measure_loop(experiment: str,
set_up_coverage_binaries(pool, experiment)
# Using Multiprocessing.Queue will fail with a complaint about
# inheriting queue.
q = manager.Queue() # pytype: disable=attribute-error
manager_queue = manager.Queue() # pytype: disable=attribute-error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

call this multiprocessing_queue

@@ -13,8 +13,6 @@
# limitations under the License.
"""Tests for run_crashes.py."""

# pylint: disable=no-self-use
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may need to keep these for now until we update pylintrc

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this. i think we will need to discuss this offline. I have some concerns. Mainly, why update .pylintrc?

I updated .pylintrc mainly because I updated pylint, which is because we updated python.
This .pylintrc is automatically generated with the latest version of pylint, which I presume contains many new settings (e.g., some default settings may have been changed to optional).
I am also working on manually merging some of our old changes to here, e.g. ignore=alembic

Happy to discuss more on this, as I am not certain which settings should be kept.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just come across another reason to update .pylintrc: I found 35 deprecated and 5 unknown pylint messages in our old .pylintrc that cause errors with the new pylint.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated .pylintrc mainly because I updated pylint, which is because we updated python.

I think (not sure) this isn't the first time we've upgraded pylint, we usually don't regenerate the entire file.

This .pylintrc is automatically generated with the latest version of pylint, which I presume contains many new settings (e.g., some default settings may have been changed to optional).

I think if we can get away without changing pylintrc now we should, the lint upgrade is incidental, to upgrading python, so it's fine if it's minimal. We can worry about being consistent later.

@DonggeLiu
Copy link
Contributor Author

DonggeLiu commented Oct 20, 2022

Merged our old .pylintrc into the new one.
Fixed almost all lint errors in the framework, except a few (which we can either ignore or need to discuss).
Errors of each fuzzers are not fixed yet, maybe that depends on the contributor of them?

@jonathanmetzman
Copy link
Contributor

Merged our old .pylintrc into the new one. Fixed almost all lint errors in the framework, except a few (which we can either ignore or need to discuss). Errors of each fuzzers are not fixed yet, maybe that depends on the contributor of them?

No i think we need to fix these :-(

@DonggeLiu
Copy link
Contributor Author

Merged our old .pylintrc into the new one. Fixed almost all lint errors in the framework, except a few (which we can either ignore or need to discuss). Errors of each fuzzers are not fixed yet, maybe that depends on the contributor of them?

No i think we need to fix these :-(

Sounds like another TODO for me today 🔖

@@ -42,6 +42,7 @@ def recreate_directory(directory, create_parents=True):

def write(path, contents, open_flags='w'):
"""Opens file at |path| with |open_flags| and writes |contents| to it."""
# pylint: disable=unspecified-encoding
with open(path, open_flags) as file_handle:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if there is a better way to fix this:
We cannot simply add encoding='utf-8' as the path can be a binary file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this function is probably a bad idea, maybe just get rid of it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I left a todo on it for another PR as it is involved in several other functions.

# Matches UBSan features enabled in OSS-Fuzz.
# See https://github.com/google/oss-fuzz/blob/master/infra/base-images/base-builder/Dockerfile#L94
# Matches UBSan features enabled in OSS-Fuzz. See
# https://github.com/google/oss-fuzz/blob/master/infra/base-images/base-builder/Dockerfile#L94
Copy link
Contributor Author

@DonggeLiu DonggeLiu Oct 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.pylintrc can ignore long URL lines, but its regex pattern needs the line to start with http/https.
Would you prefer me to fix this error like this (i.e., forcing long URL lines in code to follow the existing pattern in pylintrc), or change the pattern in .pylintrc (e.g., ignore all lines that contain a URL like the old version)?

@DonggeLiu
Copy link
Contributor Author

I reckon all errors from make presubmit are fixed now: )

@DonggeLiu
Copy link
Contributor Author

@jonathanmetzman: I reckon this is ready to be merged into #1526, please let me know what you think : )

@jonathanmetzman
Copy link
Contributor

Why not merge it here?
Do you know why CI isn't running anymore? I wonder if it's from adding new fuzzers to CI?

Copy link
Contributor

@jonathanmetzman jonathanmetzman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks

- aflpp_random_no_favs
- aflpp_random_wrs
- aflcc
- aflpp_random_wrs_rf_rp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't add these please, I think it's breaking CI. Remove them please. CI will fail but that's fine IMO

@@ -42,6 +42,7 @@ def recreate_directory(directory, create_parents=True):

def write(path, contents, open_flags='w'):
"""Opens file at |path| with |open_flags| and writes |contents| to it."""
# pylint: disable=unspecified-encoding
with open(path, open_flags) as file_handle:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this function is probably a bad idea, maybe just get rid of it.

@@ -145,8 +147,8 @@ def measure_loop(experiment: str,
logger.info('Finished measure loop.')


def measure_all_trials(experiment: str, max_total_time: int, pool, q,
region_coverage) -> bool: # pylint: disable=invalid-name
def measure_all_trials(experiment: str, max_total_time: int, pool,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove this pylint directive?

continue
member_file_handle = tar.extractfile(member)
if not member_file_handle:
logger.info('Failed to get handle to %s', member)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit end thsi with a period.

@@ -94,7 +94,8 @@ def eclipser(input_corpus, output_corpus, target_binary):
if os.listdir(input_corpus): # Specify inputs only if any seed exists.
command += ['-i', input_corpus]
print('[eclipser] Run Eclipser with command: ' + ' '.join(command))
subprocess.Popen(command)
with subprocess.Popen(command):
pass
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you disable this warning just for Popen? If you can let's just do this in .pylintrc (this is kind of burdensome for files in fuzzers/)

@@ -52,7 +52,7 @@ def build(): # pylint: disable=too-many-branches,too-many-statements
raise RuntimeError('Unsupported benchmark, unavailable grammar')
dest = os.path.join(os.environ['OUT'], 'grammar.json.gz')
shutil.copy(copy_file, dest)
os.system("gzip -d '%s'" % dest)
os.system(f"gzip -d '{dest}'")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: single quotes on outside.

.pylintrc Outdated
known-third-party=enchant
# This flag controls whether inconsistent-quotes generates a warning when the
# character used as a quote delimiter is used inconsistently within a module.
check-quote-consistency=no
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if you change this to "yes"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It finds 299 new errors, 272 of which are from different fuzzers' fuzzer.py : )

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

Copy link
Contributor

@jonathanmetzman jonathanmetzman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACtually, don't land this without removing those fuzzers from CI please.

@jonathanmetzman
Copy link
Contributor

btw I think CI builds still won't run after you undo your additions, it's because of #1536 that it's failing right now.

@DonggeLiu
Copy link
Contributor Author

Why not merge it here?

I consider this as a part of upgrading Python in #1526, as new Python (and new pylint) has new format/lint requirements.
It is a patch to fix the CI failure in #1526.

@DonggeLiu
Copy link
Contributor Author

btw I think CI builds still won't run after you undo your additions, it's because of #1536 that it's failing right now.

OK, I've reverted the commit.

@DonggeLiu
Copy link
Contributor Author

DonggeLiu commented Oct 25, 2022

Do you know why CI isn't running anymore? I wonder if it's from adding new fuzzers to CI?

I am wondering about that, too.
From the history of merged PRs, I can see that #1517 is the last PR that runs all CIs, and then my #1525 is the first PR that should have run all CIs but did not.
So I guess it must be one (or more) of the PRs in between, i.e. {#1517, #1518, #1519, #1529, #1522, #1523,#1524}.

@jonathanmetzman
Copy link
Contributor

I think if you pull CI will run again

@DonggeLiu
Copy link
Contributor Author

I think if you pull CI will run again

Thanks! It looks alright now.
Would you mind me merging this back to #1526 and fixing the fuzzers' build errors (by removing the corresponding benchmarks, etc.)?
I want to make this PR mainly about fixing lint and other presubmit errors.

@DonggeLiu
Copy link
Contributor Author

I think if you pull CI will run again

And by the way, why would the fuzzers in #1537 disable all CI build checks?

@jonathanmetzman
Copy link
Contributor

I think if you pull CI will run again

And by the way, why would the fuzzers in #1537 disable all CI build checks?

Github must have some limit that we run into silently 🤦

@DonggeLiu
Copy link
Contributor Author

Github must have some limit that we run into silently 🤦

Yeah, I guess we do have a lot of build tests in CI...
OK, I will fix the build issues in #1526 first, then come back and merge this to #1526 as discussed.

@DonggeLiu
Copy link
Contributor Author

@jonathanmetzman : Shall I merge this back to the base branch? Thanks!

Copy link
Contributor

@jonathanmetzman jonathanmetzman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@jonathanmetzman
Copy link
Contributor

@jonathanmetzman : Shall I merge this back to the base branch? Thanks!

sure!

@DonggeLiu DonggeLiu merged commit 2ba4957 into upgrade-base-image Nov 24, 2022
@DonggeLiu DonggeLiu deleted the fix_lint branch November 24, 2022 21:32
@DonggeLiu DonggeLiu mentioned this pull request Jan 9, 2023
DonggeLiu added a commit that referenced this pull request Jan 13, 2023
Fixes #1594:
1. Revert a previous lint fix (in #1529) to avoid using `with` on
subprocesses, as the context manager made local experiments fail to
launch runner instances.
2. Simplify the previous return statement, which was true by definition.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants